<html>
<head>
    <title>catch</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
	include_once('util.php');
    include_once('common.php');
    include_once('page.php');
    include_once('./lib/simple_html_dom.php');

    checkPermission();

    $target_url = 'http://zhihudaily.ahorn.me/page/';
    $page = new page();

    $html = file_get_html($target_url.'1');
    $total = getPage($html);
    $html->clear();
    $start = microtime(true);

    for ($pageCount = 1, $count = 0; $pageCount <= $total; $pageCount++) {
        print('正在分析第'.$pageCount.'页'."\n");

        $begin = microtime(true);
        $html = file_get_html($target_url.$pageCount);
        foreach($html->find("div[class=item] a") as $post)
        {
            $page->loadPage($post->href);
            $page->printToFile();

            $count++;
        }
        $html->clear();
        $end = microtime(true);

        $total = $end - $begin;
        print('第'.$pageCount.'页分析结束。花费了:'.$total."\n");
    }

    $total = $end - $start; //计算差值
    print('分析结束，共完成'.$count.'篇文章的分析。');
    print('共花时间:'.$total.'秒'."\n");
?>
</body>
</html>